package br.com.onlinebidding.facade;

import java.util.List;

import br.com.onlinebidding.dao.BidDAO;
import br.com.onlinebidding.model.Bid;

public class BidFacade {

	private BidDAO bidDAO = new BidDAO();
	
	public void insertBid(Bid bid){
		this.bidDAO.beginTransaction();
		this.bidDAO.save(bid);
		this.bidDAO.commitAndCloseTransaction();
	}
	
	public Bid findBid(int bidId){
		this.bidDAO.beginTransaction();
		Bid bid = this.bidDAO.find(bidId);
		this.bidDAO.closeTransaction();
		return bid;
	}
	
	public List<Bid> listAll(){
		this.bidDAO.beginTransaction();
		List<Bid> result = this.bidDAO.findAll();
		this.bidDAO.closeTransaction();
		return result;
	}
	
	public void deleteBid (Bid bid){
		this.bidDAO.beginTransaction();
		Bid persistedBid = this.bidDAO.find(bid.getId());
		this.bidDAO.delete(persistedBid);
		this.bidDAO.commitAndCloseTransaction();
	}
}
